//
//  ServerEngine.m
//  fugitiveVertical
//
//  Created by Eugene Bistolas on 5/13/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "ServerEngine.h"


@implementation ServerEngine
@synthesize powerups = powerups_; 
@synthesize numPowerups = numPowerups_; 

- (void) parseServerData {
    if (self.powerups) {
        [self.powerups release]; 
    }
    self.powerups = [[[NSMutableArray alloc] init] autorelease]; 
    //Grab data as string from server. 
    NSString *data =[NSString stringWithContentsOfURL: [NSURL URLWithString: @"http://dl.dropbox.com/u/403983/textfile.html"] encoding:NSASCIIStringEncoding error:nil];

    while ([data length] > 0) {
        NSString *substr = [data substringToIndex:25];
        data = [data substringFromIndex:25];
        int type = [[substr substringWithRange:NSMakeRange(1, 1)] intValue];
        double lat = [[substr substringWithRange:NSMakeRange(4, 11)] doubleValue];
        double lng = [[substr substringFromIndex:14] doubleValue];
        
        Powerup *p = [[Powerup alloc] initWithLatitude:lat longitude:lng];
        p.title = @"Powerup"; 
        NSString *subtitle = [NSString stringWithFormat:@"Type: %d", type]; 
        p.subtitle = subtitle;
        [self.powerups addObject:p]; 
        [p release]; 
        numPowerups_++; 
    }
}

- (void) dealloc {
    [super dealloc]; 
    [powerups_ release]; 
}

@end
